package com.seven.springboot.util;

/**
 * 验证工具类
 * 
 * @author liujie 2015-7-23
 */

public class ValidateUtils {
	
	/**
	 * 判断是否是有效的身份证号
	 * 
	 * @param idNo	身份证
	 * 
	 * @return 有效 true， 无效false
	 */
	public static boolean isIdentityCard(String idNo) {
		return IDCardValidate.isIDCard(idNo);
	}
	
	/**
	 * 判断是否是有效的军官证
	 * 
	 * @param militaryCardNo	军官证
	 * @return	有效true，无效false
	 */
	public static boolean isMilitaryCard(String militaryCardNo) {
		if(StringUtils.isEmpty(militaryCardNo)) {
			return false;
		}
		String regex = "\\S{8,10}";
		militaryCardNo = militaryCardNo.trim();
		if (militaryCardNo.matches(regex)) {
			return true;
		}
		return false;
	}
	
	/**
	 * 判断是否是有效的驾驶证
	 * 
	 * @param driversLicenseNo	驾驶证	
	 * @return	有效true，无效false
	 */
	public static boolean isDriversLicense(String driversLicenseNo) {
		throw new UnsupportedOperationException(
				"this operation has not implemented!!");
	}
	
	/**
	 * 判断是否是有效的护照
	 * 
	 * @param passportNo	护照
	 * @return	有效true，无效false
	 */
	public static boolean isPassport(String passportNo) {
		if(StringUtils.isEmpty(passportNo)) {
			return false;
		}
		String expression = "^[0-9A-Za-z]{8,14}";
		passportNo = passportNo.trim();
		if (passportNo.matches(expression)) {
			return true;
		}
		return false;
	}

	/**
	 * 判断是否有效的户口薄
	 * @param residenceBookletNo	户口薄	
	 * @return
	 */
	public static boolean isResidenceBooklet(String residenceBookletNo) {
		throw new UnsupportedOperationException(
				"this operation has not implemented!!");
	}
	
	/**
	 * 判断是否是有效的回乡证
	 * @param HomeReturnPermitNo	回乡证号
	 * @return
	 */
	public static boolean isHomeReturnPermit(String HomeReturnPermitNo) {
		throw new UnsupportedOperationException(
				"this operation has not implemented!!");
	}
	
	/**
	 * 判断是否是有效的港澳通行证
	 * 
	 * @param gatePassNo
	 *            通行证号
	 * @return
	 */
	public static boolean isGatePass(String gatePassNo) {
		if (StringUtils.isEmpty(gatePassNo)) {
			return false;
		}
		String regex = "^[0-9A-Za-z]{9,12}";
		gatePassNo = gatePassNo.trim();
		if (gatePassNo.matches(regex)) {
			return true;
		}
		return false;
	}

	/**
	 * 检查是否是台胞证
	 * 
	 * @param cardNo
	 * @return
	 */
	public static boolean isTaiBaoZheng(String cardNo) {
		if (StringUtils.isEmpty(cardNo)) {
			return false;
		}
		String regex = "\\d{8,11}";
		if (cardNo.matches(regex)) {
			return true;
		}
		return false;
	}
	/**
	 * 检查是否是网址
	 * 
	 * @param cardNo
	 * @return
	 */
	public static boolean isURL(String cardNo) {
		if (StringUtils.isEmpty(cardNo)) {
			return false;
		}
		String regex = "^([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~\\/])+$";
		if (cardNo.matches(regex)) {
			return true;
		}
		return false;
	}
	public static void main(String[] args) {
		System.out.println(isEmailAddress("jiliangshan@163.com"));
	}
	/**
	 * 检查是否是邮箱地址
	 * 
	 * @param cardNo
	 * @return
	 */
	public static boolean isEmailAddress(String cardNo) {
		if (StringUtils.isEmpty(cardNo)) {
			return false;
		}
		String regex = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";
		if (cardNo.matches(regex)) {
			return true;
		}
		return false;
	}

	/**
	 * 是否是有效的临时身份证
	 * 
	 * @param temporaryIdCardNo		临时身份证号
	 * @return
	 */
	public static boolean isTemporaryIdCard(String temporaryIdCardNo) {
		throw new UnsupportedOperationException(
				"this operation has not implemented!!");
	}
	
	/**
	 * 是否是有效的外国人居住证
	 * 
	 * @param residencePermit4ForeignersNo	外国人居住证号
	 * @return
	 */
	public static boolean isResidencePermit4Foreigners(String residencePermit4ForeignersNo) {
		throw new UnsupportedOperationException(
				"this operation has not implemented!!");
	}
	
	/**
	 * 是否是有效的警官证号
	 * 
	 * @param policeIdNo	警官证号
	 * @return
	 */
	public static boolean isPoliceId(String policeIdNo) {
		throw new UnsupportedOperationException(
				"this operation has not implemented!!");
	}
	/**
	 * 是数据ID
	 * @author daidalei
	 * @date 2016-11-29 上午11:43:03
	 */
	public static boolean isDataId(int dataId){
		return dataId > 0;
	}
	/**
	 * 不是数据ID
	 * @author daidalei
	 * @date 2016-11-29 上午11:43:29
	 */
	public static boolean isNotDataId(int dataId) {
		return !isDataId(dataId);
	}
	
	public static boolean isUserId(int userId) {
		return userId > 0;
	}
	
	public static boolean isHospitalId(int hospitalId) {
		return hospitalId > 0;
	}

	public static boolean isNotHospitalId(int hospitalId) {
		return !isHospitalId(hospitalId);
	}
	
	public static boolean isDepartmentId(int departmentId) {
		return departmentId > 0;
	}

	public static boolean isNotDepartmentId(int departmentId) {
		return !isDepartmentId(departmentId);
	}
	
	public static boolean isPatientId(int patientId) {
		return patientId > 0;
	}
	
	public static boolean isDiseaseId(int diseaseId) {
		return diseaseId > 0;
	}
	
	public static boolean isDutySourceId(int dutySourceId) {
		return dutySourceId > 0;
	}
	
	public static boolean isOrderId(int orderId) {
		return orderId > 0;
	}
	
	public static boolean isDoctorId(int doctorId) {
		return doctorId > 0;
	}

	public static boolean isNotDoctorId(int doctorId) {
		return !isDoctorId(doctorId);
	}
	
	public static boolean isDutyoffId(int dutyoffId) {
		return dutyoffId > 0;
	}
	
	/**
	 * 检查密码强度(数字+字母+字符 || 字母+字符 || 数字+字母 || 数字+字符 6-20位)
	 * 
	 * @param passWord
	 * @return
	 */
	public static boolean isPassWordStrong(String passWord) {
		String regex = "^((?!\\d+$)(?![a-zA-Z]+$)[a-zA-Z\\d@#$%^&_+].{5,19})+$";
		if (StringUtils.isEmpty(passWord)) {
			return false;
		}
		if (passWord.matches(regex)) {
			return true;
		}
		return false;
	}
	
	/**
	 * 座机号验证
	 * 
	 * @param telephone
	 * @return
	 */
	public static boolean isTelephone(String telephone) {
		String regex = "^\\d{3,4}-?\\d{7,9}$";
		if (StringUtils.isEmpty(telephone)) {
			return false;
		}
		if (telephone.matches(regex)) {
			return true;
		}
		return false;
	}
	
}
